Skip to content

Conversation

epage
Copy link
Contributor

@epage epage commented Sep 1, 2023

Closes #111544

@epage
Copy link
Contributor Author

epage commented Sep 1, 2023

@rustbot modify labels: +T-libs-api

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Sep 1, 2023
@rustbot
Copy link
Collaborator

rustbot commented Sep 1, 2023

r? @cuviper

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 1, 2023
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Sep 1, 2023

The Miri subtree was changed

cc @rust-lang/miri

@cuviper
Copy link
Member

cuviper commented Sep 1, 2023

The FCP approval asked for a name change: #111544 (comment)

@epage
Copy link
Contributor Author

epage commented Sep 2, 2023

Thanks, somehow I missed that

@epage epage marked this pull request as draft September 2, 2023 00:05
@rustbot rustbot added O-unix Operating system: Unix-like O-windows Operating system: Windows labels Sep 2, 2023
@rust-log-analyzer

This comment has been minimized.

@epage epage marked this pull request as ready for review September 2, 2023 01:32
@epage
Copy link
Contributor Author

epage commented Sep 2, 2023

@rustbot ready

@cuviper
Copy link
Member

cuviper commented Sep 2, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 2, 2023

📌 Commit 30292bb has been approved by cuviper

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 2, 2023
fmease added a commit to fmease/rust that referenced this pull request Sep 2, 2023
feat(std): Stabilize 'os_str_bytes' feature

Closes rust-lang#111544
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 2, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#114349 (rustc_llvm: Link to `zlib` on dragonfly and solaris)
 - rust-lang#114845 (Add alignment to the NPO guarantee)
 - rust-lang#115427 (kmc-solid: Fix `is_interrupted`)
 - rust-lang#115443 (feat(std): Stabilize 'os_str_bytes' feature)
 - rust-lang#115444 (Create a SMIR visitor)
 - rust-lang#115449 (Const-stabilize `is_ascii`)
 - rust-lang#115456 (Add spastorino on vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 43e1561 into rust-lang:master Sep 2, 2023
@rustbot rustbot added this to the 1.74.0 milestone Sep 2, 2023
@epage epage deleted the os_str branch September 2, 2023 17:02
sunshowers pushed a commit to camino-rs/camino that referenced this pull request Aug 15, 2024
Background:

When I was migrating `PathBuf` to `Utf8PathBuf`, etc, I found out some regression in our benchmarks. Then I found out `as_str` is actually not cost-free as in the older version of rustc there's no way to get the underlying bytes out of an `OsStr` until 1.74.0.

In this PR, with the help of [`OsStr::as_encoded_bytes`](rust-lang/rust#115443) was stabilized in 1.74.0, We can perform a cost-free conversion from `&OsStr` to `&str` with constraint of it's underlying bytes are `UTF-8` encoded.

Benchmark:

With the benchmark included in the PR, the time cost is a constant now.

Result:
```
// String length of 10
osstr to_str/10 
                        time:   [5.9769 ns 5.9913 ns 6.0060 ns]
osstr as_encoded_bytes/10 
                        time:   [554.90 ps 558.32 ps 562.19 ps]

// String length of 100
osstr to_str/100
                        time:   [6.6113 ns 6.6250 ns 6.6404 ns]
osstr as_encoded_bytes/100
                        time:   [553.18 ps 557.33 ps 561.68 ps]

// String length of 1000
osstr to_str/1000
                        time:   [26.990 ns 27.033 ns 27.086 ns]
osstr as_encoded_bytes/1000
                        time:   [553.66 ps 560.67 ps 570.42 ps]

// String length of 10000
osstr to_str/10000
                        time:   [310.17 ns 310.77 ns 311.32 ns]
osstr as_encoded_bytes/10000
                        time:   [550.98 ps 555.16 ps 559.53 ps]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-unix Operating system: Unix-like O-windows Operating system: Windows S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking Issue for os_str_bytes
5 participants